{extend name="index/iframe" /}

{block name="content"}
<form class="layui-form layui-form-my" action="">
    <input type="hidden" name="id" value="{$Think.get.id}">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">费用类型</label>
            <div class="layui-input-inline">
                <select name="pay_type" lay-filter="pay_type" id="pay_type" lay-verify="required" disabled>
                    <option value="1" {$find.server_price==0 ? 'selected' : ''}>CPS和联运</option>
                    <option value="2" {$find.server_price==0 ? '' : 'selected'}>服务器费用</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">结账类型</label>
            <div class="layui-input-inline">
                <select name="balance_type" lay-filter="balance_type" id="balance_type" disabled>
                    <option value="">全部</option>
                    {foreach $Think.config.balance_type as $k=>$v}
                    <option value="{$k}" {$k==$find.balance_type ? 'selected' : ''}>{$v}</option>
                    {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">选择游戏</label>
            <div class="layui-input-inline">
                {MyTag:game type='manage' id="$find['game_id']" disabled="1" /}
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">对账日期</label>
            <div class="layui-input-inline" id="audit_time">
                <input type="text" value="{$find.start_time} - {$find.end_time}" name="date" class="layui-input layui-disabled" id="date" placeholder="yyyy-MM-dd - yyyy-MM-dd" autocomplete="off" disabled>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">发票类型</label>
            <div class="layui-input-inline">
                <select name="invoice_type" lay-filter="invoice_type" id="invoice_type" disabled>
                    <option value="">全部</option>
                    {volist name="$Think.config.cp_invoice_type" id="vo"}
                    <option value="{$vo.type}" {$vo['name']==$find['invoice_type'] ? 'selected' : ''} rate="{$vo.rate}">{$vo.name}</option>
                    {/volist}
                </select>
            </div>
        </div>
    </div>
    <hr>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">CPS充值</label>
            <div class="layui-input-inline">
                <input type="tel" value="{$find.cps_fixed_price}" name="cps_fixed_price" id="cps_fixed_price" lay-verify="required" placeholder="元" autocomplete="off" class="layui-input layui-disabled" disabled>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">联运充值</label>
            <div class="layui-input-inline">
                <input type="text" value="{$find.sdk_fixed_price}" name="sdk_fixed_price" id="sdk_fixed_price" lay-verify="required" placeholder="元" autocomplete="off" class="layui-input layui-disabled" disabled>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">CPS充值</label>
            <div class="layui-input-inline">
                <input type="tel" value="{$find.cps_pay_price}" name="cps_pay_price" id="cps_pay_price" lay-verify="required" placeholder="元" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">联运充值</label>
            <div class="layui-input-inline">
                <input type="text" value="{$find.sdk_pay_price}" name="sdk_pay_price" id="sdk_pay_price" lay-verify="required" placeholder="元" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">渠道费率</label>
            <div class="layui-input-inline">
                <input type="text" value="{$find.channel_rate|substr=0,-1}" name="channel_rate" id="channel_rate" lay-verify="required" placeholder="%" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">税率</label>
            <div class="layui-input-inline">
                <input type="text" value="{$find.tax_rate|substr=0,-1}" name="tax_rate" id="tax_rate" lay-verify="required" placeholder="%" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">结算比例</label>
            <div class="layui-input-inline">
                <input type="text" value="{$find.pay_rate|substr=0,-1}" name="pay_rate" id="pay_rate" lay-verify="required" placeholder="%" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">CPS结算</label>
            <div class="layui-input-inline">
                <input type="tel" value="{$find.cps_total_price}" name="cps_total_price" id="cps_total_price" lay-verify="required" placeholder="元" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">联运结算</label>
            <div class="layui-input-inline">
                <input type="text" value="{$find.sdk_total_price}" name="sdk_total_price" id="sdk_total_price" lay-verify="required" placeholder="元" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">服务器费用</label>
            <div class="layui-input-inline">
                <input type="text" value="{$find.server_price}" name="server_price" id="server_price" placeholder="元" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">合计</label>
            <div class="layui-input-inline">
                <input type="text" value="{$find.all_total_price}" name="all_total_price" id="all_total_price" lay-verify="required" placeholder="元" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea name="remark" placeholder="请输入备注" class="layui-textarea">{$find.remark}</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn my-btn" lay-submit="" lay-filter="submitBtn">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
{/block}

{block name="css"}{/block}

{block name="js"}
<script>
    layui.use(['form', 'layedit', 'laydate', 'upload', 'element'], function(){
        var form = layui.form
            ,$ = layui.$
            ,layer = layui.layer;

        //input离开事件
        $('#cps_pay_price').blur(function(){
            var cps_pay_price = $('#cps_pay_price').val()
                ,pay_rate = $('#pay_rate').val()
                ,channel_rate = $('#channel_rate').val()
                ,tax_rate = $('#tax_rate').val()
                ,sdk_total_price = $('#sdk_total_price').val()
                ,cps_total_price = (cps_pay_price*(pay_rate/100)*(1-(channel_rate/100))*(1-(tax_rate/100))).toFixed(2)
                ,all_total_price = (parseFloat(cps_total_price)+parseFloat(sdk_total_price)).toFixed(2);
            $('#cps_total_price').val(cps_total_price);
            $('#all_total_price').val(all_total_price);
        })
        $('#sdk_pay_price').blur(function(){
            var sdk_pay_price = $('#sdk_pay_price').val()
                ,pay_rate = $('#pay_rate').val()
                ,channel_rate = $('#channel_rate').val()
                ,tax_rate = $('#tax_rate').val()
                ,cps_total_price = $('#cps_total_price').val()
                ,sdk_total_price = (sdk_pay_price*(pay_rate/100)*(1-(channel_rate/100))*(1-(tax_rate/100))).toFixed(2)
                ,all_total_price = (parseFloat(cps_total_price)+parseFloat(sdk_total_price)).toFixed(2);
            $('#sdk_total_price').val(sdk_total_price);
            $('#all_total_price').val(all_total_price);
        })
        $('#channel_rate').blur(function(){
            var cps_pay_price = $('#cps_pay_price').val()
                ,sdk_pay_price = $('#sdk_pay_price').val()
                ,pay_rate = $('#pay_rate').val()
                ,channel_rate = $('#channel_rate').val()
                ,tax_rate = $('#tax_rate').val()
                ,cps_total_price = (cps_pay_price*(pay_rate/100)*(1-(channel_rate/100))*(1-(tax_rate/100))).toFixed(2)
                ,sdk_total_price = (sdk_pay_price*(pay_rate/100)*(1-(channel_rate/100))*(1-(tax_rate/100))).toFixed(2)
                ,all_total_price = (parseFloat(cps_total_price)+parseFloat(sdk_total_price)).toFixed(2);

            $('#cps_total_price').val(cps_total_price);
            $('#sdk_total_price').val(sdk_total_price);
            $('#all_total_price').val(all_total_price);
        })
        $('#tax_rate').blur(function(){
            var cps_pay_price = $('#cps_pay_price').val()
                ,sdk_pay_price = $('#sdk_pay_price').val()
                ,pay_rate = $('#pay_rate').val()
                ,channel_rate = $('#channel_rate').val()
                ,tax_rate = $('#tax_rate').val()
                ,cps_total_price = (cps_pay_price*(pay_rate/100)*(1-(channel_rate/100))*(1-(tax_rate/100))).toFixed(2)
                ,sdk_total_price = (sdk_pay_price*(pay_rate/100)*(1-(channel_rate/100))*(1-(tax_rate/100))).toFixed(2)
                ,all_total_price = (parseFloat(cps_total_price)+parseFloat(sdk_total_price)).toFixed(2);

            $('#cps_total_price').val(cps_total_price);
            $('#sdk_total_price').val(sdk_total_price);
            $('#all_total_price').val(all_total_price);
        })
        $('#pay_rate').blur(function(){
            var cps_pay_price = $('#cps_pay_price').val()
                ,sdk_pay_price = $('#sdk_pay_price').val()
                ,pay_rate = $('#pay_rate').val()
                ,channel_rate = $('#channel_rate').val()
                ,tax_rate = $('#tax_rate').val()
                ,cps_total_price = (cps_pay_price*(pay_rate/100)*(1-(channel_rate/100))*(1-(tax_rate/100))).toFixed(2)
                ,sdk_total_price = (sdk_pay_price*(pay_rate/100)*(1-(channel_rate/100))*(1-(tax_rate/100))).toFixed(2)
                ,all_total_price = (parseFloat(cps_total_price)+parseFloat(sdk_total_price)).toFixed(2);
            $('#cps_total_price').val(cps_total_price);
            $('#sdk_total_price').val(sdk_total_price);
            $('#all_total_price').val(all_total_price);
        })
        $('#cps_total_price').blur(function(){
            var cps_total_price = $('#cps_total_price').val()
                ,sdk_total_price = $('#sdk_total_price').val()
                ,all_total_price = (parseFloat(cps_total_price)+parseFloat(sdk_total_price)).toFixed(2);
            $('#all_total_price').val(all_total_price);
        })
        $('#sdk_total_price').blur(function(){
            var cps_total_price = $('#cps_total_price').val()
                ,sdk_total_price = $('#sdk_total_price').val()
                ,all_total_price = (parseFloat(cps_total_price)+parseFloat(sdk_total_price)).toFixed(2);
            $('#all_total_price').val(all_total_price);
        })
        $('#server_price').blur(function(){
            var server_price = $('#server_price').val()
                ,pay_rate = $('#pay_rate').val()
                ,channel_rate = $('#channel_rate').val()
                ,tax_rate = $('#tax_rate').val()
                ,all_total_price = (server_price*(pay_rate/100)*(1-(channel_rate/100))*(1-(tax_rate/100))).toFixed(2);
            $('#all_total_price').val(all_total_price);
        })
        //提交
        form.on('submit(submitBtn)', function(data){
            var str = '';
            layer.msg('生成中....', {icon: 1, time: 2000});
            for(key in data.field){
                str += key + '=' + data.field[key] + '&';
            }
            window.location.href = '{:url("AuditCpMng/edit")}?'+str.substring(0, str.length-1);
            setTimeout(function(){
                window.location.reload();
            }, 2000);
            return false;
        });
    });
</script>
{/block}